﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class UserPanel : Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["Login"] != null)
            {
                ServiceReference.ServiceClient service = new ServiceReference.ServiceClient();
                ServiceReference.Person pers = (ServiceReference.Person)service.GetById("Person", ((ServiceReference.Account)Session["Login"]).personId);
                service.Close();
                fNameTextBox.Text = pers.fName;
                sNameTextBox.Text = pers.sName;
                emailTextBox.Text = ((ServiceReference.Account)Session["Login"]).email;
                passportTextBox.Text = pers.passportNo;
                addressTextBox.Text = pers.address;
                phoneTextBox.Text = pers.phone;
                if (pers.gender==true)
                    RadioButton1.Checked = true;
                else
                    RadioButton2.Checked = true;
               
            }
            else
                Server.Transfer("Register.aspx");
        }
    }

    protected void update(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            ServiceReference.ServiceClient service = new ServiceReference.ServiceClient();
            ServiceReference.Person pers = new ServiceReference.Person();
            
            pers.fName = fNameTextBox.Text;
            pers.sName = sNameTextBox.Text;
            pers.address = addressTextBox.Text;
            pers.passportNo = passportTextBox.Text;
            pers.phone = phoneTextBox.Text;
            pers.gender = true;
            
            pers.personId = ((ServiceReference.Account)Session["Login"]).personId;
            service.updatePerson(pers);

            service.Close();
        }
            
    }
}